home *** CD-ROM | disk | FTP | other *** search
/ Amoszine 8 / Amoszine 8 (Disk 1 of 3).adf / ARTS / MA_Extension_Tutor_Pt2.asc < prev    next >
Text File  |  1998-04-26  |  7KB  |  213 lines

  1. Extension_Tutorial_Part2 (18/7/1995)
  2. -------------------------------------
  3.  
  4. I hope you've enjoyed the first part of the extension tutorial and
  5. maybe you have made an interesting routine yourself.
  6. If so, feel free to share it with the rest of the AMOS community.
  7.  
  8. I've decided to move from 'ready to compile' format to a 'cut and insert'
  9. format.
  10. Each new command/function will consist of three parts:
  11.  1) Command description.
  12.  2) Token description.
  13.  3) Any data to be inserted into the extension data area.
  14.  4) The routine itself.
  15.  
  16. To include a routine into the your extension, you have to insert
  17. the token description into the token list and insert the routine at
  18. a free label.
  19.  
  20. Have fun!
  21.  
  22. MANUEL ANDRE
  23. ARBEIDERSSTRAAT Nr. 9
  24. 2600 BERCHEM
  25. Belgium
  26.  
  27. Chapter Three.
  28. ==============
  29.  
  30. Accessing Amos system pointers, variables and structures.
  31. ---------------------------------------------------------
  32.  
  33. When Amos is loaded, several libraries are opened and ready for usage.
  34. These can be found in the _wequ.s file.
  35. Also many variables and structures are set up for direct use.
  36. All of these are accessed through address register A5.
  37.  
  38.  
  39. A new command will show how to use them...
  40.  
  41. Az Triangle X1,Y1 To X2,Y2
  42.   Draws a triangle starting from X1,Y1 to X1,Y2 to X2,Y2 to X1,Y1
  43.   None of the parameters may be ommitted.
  44.  
  45.  
  46. Token definition for Az Triangle X1,Y1 To X2,Y2
  47.  
  48.     DC.W    L_AZ_TRIANGLE,-1
  49.     DC.B    "az triangl","e"+$80,"I0,0t0,0",-1
  50.  
  51.  
  52. No new data to be inserted into the extension data zone.
  53.  
  54.  
  55. Code for Az Triangle X1,Y1 To X2,Y2
  56.  
  57. L_AZ_TRIANGLE    EQU    4
  58. L4        MOVE.L    (A3)+,D7        Y2 \
  59.         MOVE.L    (A3)+,D6        X2 |
  60.         MOVE.L    (A3)+,D5        Y1 |-> Reversed order !
  61.         MOVE.L    (A3)+,D4        X1 /
  62. ;        Push A6 onto the stack, we need this register 
  63.         MOVE.L    A6,-(SP)
  64.         MOVE.L    T_GFXBASE(A5),A6    for the Graphics library base.
  65.         MOVE.L    T_RASTPORT(A5),A1    Load A1 with RastPort adress.
  66.         MOVE.L    A1,D3            RastPort adress in spare reg.
  67. ;
  68. ;We have received all four coordinates in registers D4 to D7.
  69. ;Registers D4 to D7 are a good place to put them, because their contents
  70. ;are NOT trashed by the two Gaphics Library calls we are going to use.
  71. ;Beware, register A1 will be trashed AFTER every call to Move or Draw, so
  72. ;we have to reload it with the RastPort address after each call.
  73. ;Instead of fetching this address every time from memory, we store it in a
  74. ;spare data register that will not be trashed.
  75. ;This will save some precious CPU time...
  76. ;Alert minds will also spot that the address register A6 is only loaded
  77. ;once with the Graphics library base.
  78. ;This is also a, rather risky, technique to speed up things a little bit more.
  79. ;Risky, because it is only to be used when you are not calling routines from
  80. ;other libraries...
  81. ;Offcourse, one could allways try..and die ;-)
  82. ;
  83.         MOVE.L    D4,D0            X1 -> D0
  84.         MOVE.L    D5,D1            Y1 -> D1
  85.         JSR    -240(A6)        Move(rastp,x,y)(A1,D0,D1)
  86.         MOVE.L    D4,D0            X1 -> D0
  87.         MOVE.L    D7,D1            Y2 -> D1
  88.         MOVE.L    D3,A1            Restore RastPort adress.
  89.         JSR    -246(A6)        Draw(rastp,x,y)(A1,D0,D1)
  90.         MOVE.L    D6,D0            X2 -> D0
  91.         MOVE.L    D7,D1            Y2 -> D1
  92.         MOVE.L    D3,A1            Restore RastPort adress.
  93.         JSR    -246(A6)        Draw(rastp,x,y)(A1,D0,D1)
  94.         MOVE.L    D4,D0            X1 -> D0
  95.         MOVE.L    D5,D1            Y1 -> D1
  96.         MOVE.L    D3,A1            Restore RastPort adress.
  97.         JSR    -246(A6)        Draw(rastp,x,y)(A1,D0,D1)
  98. ;        Pop our saved value from the stack, else crash!
  99.         MOVE.L    (SP)+,A6
  100.         RTS                Amos back in control
  101.  
  102.  
  103.  
  104. A small comment on the RastPort structure.
  105. It is a vital part of the Amiga ® display building blocks when dealing
  106. with most of the graphical operations, such as drawing lines, plotting
  107. points, etc, etc...
  108.  
  109. Like allmost anything on the Amiga ®, it is organized as a structure of
  110. a certain lenght.
  111.  
  112. Let's examine some interesting parts of it.
  113.  
  114.  STRUCTURE  RastPort,0        Hey, a structure!
  115. ;Not interested at this time, sorry...
  116.    LONG     rp_Layer
  117. ;Contains the pointer to it's BitMap, containing amongst other things, the 
  118. ;actual displayed memory.
  119.    LONG     rp_BitMap
  120. ;Contains the address that points to the pattern that will be used when filling
  121. ;area's of the screen.
  122.    LONG     rp_AreaPtrn        
  123. ;Contains the address that points to our temporary RastPort.
  124. ;See the Set Tempras command.
  125.    LONG     rp_TmpRas
  126. ;Not interested at this time, sorry...
  127.    LONG     rp_AreaInfo
  128. ;Not interested at this time, sorry...
  129.    LONG     rp_GelsInfo
  130. ;This one is only 1 byte wide and holds which bitplanes of this rp_BitMap
  131. ;are to be updated, depending on the colour you're drawing with.
  132. ;Each bit represents a bitplane and is selected when set.
  133. ;It is normally set to $FF (all bitplanes).
  134.    BYTE     rp_Mask
  135. ;The foreground pen (colour).
  136.    BYTE     rp_FgPen
  137. ;The background pen (colour).
  138.    BYTE     rp_BgPen
  139. ;The outline pen when doing areafills (colour).
  140.    BYTE     rp_AOLPen
  141. ;The drawmode : 0 = JAM1 , 1 = JAM2 , 2 = COMPLEMENT , 4 = INVERSED
  142.    BYTE     rp_DrawMode
  143. ;Not interested at this time, sorry...
  144.    BYTE     rp_AreaPtSz
  145. ;Not interested at this time, sorry...
  146.    BYTE     rp_linpatcnt
  147. ;Just included for boundary reasons...
  148.    BYTE     rp_Dummy
  149. ;Not interested at this time, sorry...
  150.    WORD     rp_Flags
  151. ;16 bit pattern to be used when drawing lines.
  152.    WORD     rp_LinePtrn
  153. ;The X-coordinate of our graphical cursor.
  154.    WORD     rp_cp_x
  155. ;The Y-coordinate of our graphical cursor.
  156.    WORD     rp_cp_y
  157. ;Not interested at this time, sorry...    \
  158.    STRUCT   rp_minterms,8        |
  159.    WORD     rp_PenWidth            |
  160.    WORD     rp_PenHeight        |
  161.    LONG     rp_Font            |
  162.    BYTE     rp_AlgoStyle        |
  163.    BYTE     rp_TxFlags            |
  164.    WORD     rp_TxHeight            |
  165.    WORD     rp_TxWidth            |
  166.    WORD     rp_TxBaseline        |
  167.    WORD     rp_TxSpacing        |
  168.    APTR     rp_RP_User            |
  169.    STRUCT   rp_longreserved,8        |
  170.     ifnd    GFX_RASTPORT_1_2    |
  171.    STRUCT   rp_wordreserved,14        |
  172.    STRUCT   rp_reserved,8        |
  173.     endc                /
  174. ;Defines the lenght of the rastport structure.
  175.    LABEL    rp_SIZEOF
  176.  
  177. Hmm, very interesting, but how to access all this fields by name?
  178. You'll have to 'include' the definition of a rastport into you program.
  179. Where do we find this file?
  180. If you are using one of the commercial assemblers, it is very likely
  181. that you will find it here... INCLUDE:Graphics/rastport.i
  182. So...where does this leave us now???
  183.  
  184. We are going to make our triangle command even faster!!!
  185.  
  186. Instead of using the graphics.library Move function, which updates the
  187. rp_cp_x and rp_cp_y values, we are going to poke them ourselves.
  188. Just replace the JSR    -$240(A6) line with MOVEM.W  D4-5,rp_cp_x(A1)
  189. and remove the two MOVE.L's...
  190.  
  191. MOVEM.W ????     Means : MOVE Multiple Words (16 bit)
  192. D4-5    ????     Means : register D4 and D5
  193.  
  194. Another example :
  195.      MOVEM.L  D0-3/D5/D7,-(SP)
  196. MOVEM.L        Means : MOVE Multiple Longwords (32 bit)
  197. D0-3/D5/D7    Means : registers D0 to D3, skip D4, move D5, skip D6, move D7.
  198.  
  199. I know, poking directly into the rastport structure doesn't sound to be 
  200. very legal, but it works...
  201. Some OS fanatics will shoot you for doing this, because your code is no longer
  202. fully compatible with newer versions of the graphics.library to come.
  203. But one could wait forever... So if you want the extra speed, shoot the
  204. OS fanatics!
  205.  
  206. I hope you enjoyed the second part of this tutorial and if you would like
  207. to see a special topic to be covered in one of the following tutorials...
  208. Drop me a letter.
  209.  
  210. Happy programming.
  211.  
  212.         Manuel.
  213.